package beans;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.NamingException;

import tools.DBManager;

public class AssembleBean {
	private  int componentID;
	private  int componentNO;
	
	private Connection conn = null;
	private Statement stmt = null;
	private ResultSet rs = null;
	
	public int getComponentID() {
		return componentID;
	}

	public void setComponentID(int componentID) {
		this.componentID = componentID;
	}

	public int getComponentNO() {
		return componentNO;
	}

	public void setComponentNO(int componentNO) {
		this.componentNO = componentNO;
	}

	public AssembleBean(){
		
	}
	
	
	public boolean insertAssemble(int ProductID){
		try{
			conn = DBManager.getConnection();
			stmt = DBManager.getStatement(conn);
			String sqlCmd = String.format("SELECT * FROM t_assemble");
			rs = stmt.executeQuery(sqlCmd);
			
			rs.last();
			rs.moveToInsertRow();
			
			rs.updateInt("ProductID", ProductID);
			rs.updateInt("ComponentID", componentID);
		    rs.updateInt("Quantity",componentNO);
		    
			rs.insertRow();
			
			
		} catch (SQLException sqlException){
			
		} catch (NamingException namingException){
			
		} finally{
			DBManager.close(rs);
			DBManager.close(stmt);
			DBManager.close(conn);
		}
		return true;
	}
}
